package com.cheboohui.iqs.spider.pingan.price;

import com.alibaba.fastjson.JSONObject;

/***
 * 请求判断（自定义第三步和自定义第四步）
 * 
 * @author xielonghai
 *
 */
public class RequestJudge {

	/**
	 * 判断是否进行下一步
	 * 
	 * @param request
	 *            上一步请求返回json
	 * @param i
	 *            自定义步骤(3,4,0)
	 * @return
	 */
	public static boolean judge(JSONObject request, int i) {
		boolean isAutoSaveFlag = request.getBoolean("isAutoSaveFlag");
		String processType = request.getString("processType");
		switch (i) {
		case 3:
			return "chooseVehType".equals(processType) && !isAutoSaveFlag;

		case 4:
			return "renewalAndC51DisTax".equals(processType) && !isAutoSaveFlag;

		case 2:
			return "allDone".equals(processType) || isAutoSaveFlag;

		case 1:
			return "allDone".equals(processType) && !isAutoSaveFlag;

		case 0:
			return "allDone".equals(processType) && isAutoSaveFlag;

		case 5:
			return "afterForceQuote".equals(processType) && !isAutoSaveFlag;
		case 6:
			return "chooseDecisionTree".equals(processType) && !isAutoSaveFlag;

		default:
			return false;
		}
	}

	/*** 交强险重复不能报价判断 ***/
	public static boolean traJudge(JSONObject response) {
		try {
			String errorMessage = response.getJSONObject("c51CaculateResult").getJSONObject("c51ResultDTO")
					.getString("errorMessage");
			if (errorMessage.indexOf("重复投保") >= 0)
				return true;
			else
				return false;
		} catch (Exception e) {
			return false;
		}
	}

	/** 车型判断---选择车型与平台返回车型 ***/
	public static JSONObject carJudge(JSONObject response, String carModel) {
		JSONObject r = new JSONObject();
		try {
			String reMOdel = response.getJSONObject("voucher").getJSONObject("vehicleTarget").getString("autoModelCode")
					.trim();
			if (!reMOdel.equals(carModel.trim())) {
				r.put("state", true);
				r.put("autoModelCode", reMOdel);
			} else
				r.put("state", false);
		} catch (Exception e) {
			r.put("state", true);
			r.put("autoModelCode", "");
		}
		return r;
	}
}
